﻿
using MediatR;
using Warehouse.API.Applcation.Command.WarehouseCommand;
using Warehouse.Infrstructre.Interface;
namespace Warehouse.API.Applcation.CommandHandlers.WarehouseCommandHndlers
{
    public class BatchWarehouseCommandHandlers : IRequestHandler<BatchWarehouseCommand, int>
    {
        private readonly IWarehouseRepository _warehouse;

        public BatchWarehouseCommandHandlers(IWarehouseRepository warehouse)
        {
            _warehouse = warehouse;
        }

        public async Task<int> Handle(BatchWarehouseCommand request, CancellationToken cancellationToken)
        {
            var list = (await _warehouse.GetAllAsyns()).Where(x => request.Ids.Contains(x.WarehouseId)).ToList();
            if (request.Code == 1)
            {
                foreach (var item in list)
                {
                    item.IsDel = true;
                    await _warehouse.UpdateAsync(item);
                }
            }
            if (request.Code == 2)
            {
                foreach (var item in list)
                {

                }
            }
            if (request.Code == 3)
            {
                foreach (var item in list)
                {

                }
            }
            return 1;

        }
    }
}
